﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.SceneControl.Scene;
using Engine;
using Engine.SceneControl;
using Engine.Material;
using Microsoft.Xna.Framework.Graphics;

namespace Etapa1.Screens
{
    public class ShadowTechnic : IRenderTechnic
    {
       
       
        ShadowShader ss;
        EngineStuff engine;
        List<DecoratedMaterial> _decs2= new List<DecoratedMaterial>();

        #region IRenderTechnic Members

        public void Initialization(IRenderHelper render, Engine.SceneControl.IWorld world, Engine.EngineStuff engine)
        {
            this.engine = engine;
            ss = new ShadowShader();
            ss.Initialize(engine);

            foreach (IObject item in world.Objects)
            {

                DecoratedMaterial dm2 = new DecoratedMaterial(item.Material, ss);
                item.Material = dm2;
                _decs2.Add(dm2);
                ss.Update(item, world.Lights);

            }
            render.SetQuadEffect(null);

        }

        public void ExecuteTechnic(IRenderHelper render, Engine.SceneControl.IWorld world)
        {
            engine.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, engine.BackGroundColor, 1.0f, 0);

            foreach (DecoratedMaterial item in _decs2)
            {
                item.OPMode = true;
                item.Shadder.EffectParameter["xTexture"].SetValue(render["Deep"]);
            }

            render.SetUpRenderTarget(Engine.SceneControl.Scene.RenderTarget.VIDEO, RenderType.NORMALSCENE);
            render.RenderSceneWithMaterial("Shadow");

            foreach (DecoratedMaterial item in _decs2)
            {
                item.OPMode = false;
            }            

        }

        public string TechnicName
        {
            get { return "shadow"; }
        }


        #endregion
    }
}
